package com.mvd.app.activity;

import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.StrictMode;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.google.gson.Gson;
import com.kongzue.dialog.v3.WaitDialog;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.mvd.app.R;
import com.mvd.app.adapter.TianjinAdapter;
import com.mvd.app.api.ApiConfig;
import com.mvd.app.application.BaseApplication;
import com.mvd.app.commons.DateUtil;
import com.mvd.app.commons.JsonUtil;
import com.mvd.app.commons.PDALogUtils;
import com.mvd.app.commons.SharedPreferencesUtils;
import com.mvd.app.commons.UtilsLog;
import com.mvd.app.model.CarsInforModel;
import com.mvd.app.model.DownLineModel;
import com.mvd.app.model.TianjinModel;
import com.mvd.app.model.TianjinPhotoModel;
import com.mvd.app.widget.MyListView2;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class TianjinActivity extends BaseActivity implements ApiConfig {
    @BindView(R.id.ac_tianjin_vin)
    EditText acTianjinVin;
    @BindView(R.id.ac_tianjin_jysj)
    TextView acTianjinJysj;
    @BindView(R.id.ac_tianjin_btn)
    Button acTianjinBtn;
    @BindView(R.id.ac_tv_tianjin_phtext1)
    TextView acTvTianjinPhtext1;
    @BindView(R.id.ac_ib_tianjin_photo1)
    ImageView acIbTianjinPhoto1;
    @BindView(R.id.ac_tv_tianjin_phtext2)
    TextView acTvTianjinPhtext2;
    @BindView(R.id.ac_ib_tianjin_photo2)
    ImageView acIbTianjinPhoto2;
    @BindView(R.id.ac_tv_tianjin_phtext3)
    TextView acTvTianjinPhtext3;
    @BindView(R.id.ac_ib_tianjin_photo3)
    ImageView acIbTianjinPhoto3;
    @BindView(R.id.ac_btn_test_photo)
    Button acBtnTestPhoto;
    @BindView(R.id.ac_tianjin_carPlate)
    EditText acTianjinCarPlate;
    @BindView(R.id.ac_tianjin_btn_cp)
    Button acTianjinBtnCp;
    @BindView(R.id.popPosition)
    LinearLayout popPosition;
    @BindView(R.id.ac_tv_tianjin_phtext4)
    TextView acTvTianjinPhtext4;
    @BindView(R.id.ac_ib_tianjin_photo4)
    ImageView acIbTianjinPhoto4;
    @BindView(R.id.ac_tianjin_PlatformSN)
    EditText acTianjinPlatformSN;
    //    @BindView(R.id.ac_btn_yu_jian)
//    Button acBtnYuJian;
    private TianjinActivity instances;
    final Calendar ca = Calendar.getInstance();
    int mYear, mMonth, mDay;
    final int DATE_DIALOG = 1;
    private List<CarsInforModel> carsInforModels;
    private TianjinAdapter tianjinAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tianjin);
        ButterKnife.bind(this);
        setBackBtn();
        setTopTitle("查看照片");
        instances = this;
        mYear = ca.get(Calendar.YEAR);
        mMonth = ca.get(Calendar.MONTH);
        mDay = ca.get(Calendar.DAY_OF_MONTH);
        Log.e("路径==", Environment.getExternalStorageDirectory().getPath() + "/myvideo/");
        if (Build.VERSION.SDK_INT > 9) {
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);
        }

    }

    @OnClick({R.id.ac_tianjin_jysj, R.id.ac_tianjin_btn, R.id.ac_btn_test_photo, R.id.ac_tianjin_btn_cp})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ac_tianjin_jysj:
                showDialog(DATE_DIALOG);
                break;
            case R.id.ac_tianjin_btn:
                String clsbdh = acTianjinVin.getText().toString().trim();//vin
                String jysj = acTianjinJysj.getText().toString().trim();//时间
                if (!TextUtils.isEmpty(clsbdh) && !TextUtils.isEmpty(jysj)) {
                    getQuery(clsbdh, jysj);
                } else {
                    Toast.makeText(instances, "请补全查询条件", Toast.LENGTH_LONG).show();
                }
                break;
            case R.id.ac_btn_test_photo:
//                testPhoto();
                String clsbdh2 = acTianjinVin.getText().toString().trim();//vin
                String jysj2 = acTianjinJysj.getText().toString().trim();//时间
                String carNo = acTianjinCarPlate.getText().toString().trim(); //车牌号
                String platformSN = acTianjinPlatformSN.getText().toString().trim();
                String[] PhotoType = {"0111", "0112", "0113", "0209"};
                if (!TextUtils.isEmpty(clsbdh2) && !TextUtils.isEmpty(jysj2) &&
                        !TextUtils.isEmpty(carNo) && !TextUtils.isEmpty(platformSN)) {
//                    for (int i = 0; i < PhotoType.length; i++) {
//                        getPhoto(clsbdh2, jysj2, platformSN, carNo, PhotoType[i], i);
//                    }
                    getPhoto0111(clsbdh2, jysj2, platformSN, carNo);
                    getPhoto0112(clsbdh2, jysj2, platformSN, carNo);
                    getPhoto0113(clsbdh2, jysj2, platformSN, carNo);
                    getPhoto0209(clsbdh2, jysj2, platformSN, carNo);
                } else {
                    Toast.makeText(instances, "请补全查询条件", Toast.LENGTH_LONG).show();
                }
                break;
            case R.id.ac_tianjin_btn_cp:
                String carPlate = acTianjinCarPlate.getText().toString();
                if (carPlate.length() < 5) {
                    Toast.makeText(instances, "请至少输入五位车牌号码", Toast.LENGTH_LONG).show();
                } else {
                    searchCar(carPlate);
                }
                break;
//            case R.id.ac_btn_yu_jian:
//                break;
        }
    }

    //    //天津---查询车辆报告
//    private void tianJin_getCarReport() {
//        TianJinCarReport modle = new TianJinCarReport();
//        modle.setBrand(carsInforModel.getBrand());
//        modle.setCarModel(carsInforModel.getCarModel());
//        modle.setPDAType("PDA");
//        modle.setBH("");
//        Gson gson = new Gson();
//        String jsonStr = gson.toJson(modle);
//        String logStr = "\n" + "天津---查询车辆报告---" + "\n" +
//                "json::" + jsonStr + "\n" +
//                "URL::" + SharedPreferencesUtils.getIP(instances) + GET_CAR_REPORT;
//        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//        UtilsLog.e("天津---查询车辆报告---jsonStr==" + jsonStr);
//        UtilsLog.e("天津---查询车辆报告---url==" + SharedPreferencesUtils.getIP(this) + GET_CAR_REPORT);
//        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + GET_CAR_REPORT)
//                .tag(this)
//                .upJson(jsonStr)
//                .execute(new StringCallback() {
//                    @Override
//                    public void onStart(Request<String, ? extends Request> request) {
//                        super.onStart(request);
////                        CommonUtils.showLoadingDialog(instances, "加载中...");
//                    }
//
//                    @Override
//                    public void onSuccess(Response<String> response) {
//                        String result = response.body().trim();
//                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
//                        UtilsLog.e("天津---查询车辆报告-result==" + result);
//                        UtilsLog.e("天津---查询车辆报告-newResult==" + newResult);
////                        UtilsLog.e("天津---查询车辆报告-result=22=" + result.substring(1, result.length() -
////                                1));
//                        String logStr = "\n" + "天津---查询车辆报告----请求成功" + "\n" +
//                                "result::" + response.body() + "\n" + "newResult::" + newResult + "\n";
//                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
//                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
//                                (newResult) && !"[]".equals(result)) {
////                            String finalResult =
//                            try {
//                                JSONObject jsonObject = new JSONObject(newResult);
//                                String finalResult = jsonObject.getJSONObject("root").getJSONObject("body").toString();
//                                String logStr2 = "\n" + "天津---查询车辆报告----请求成功" + "\n" +
//                                        "finalResult::" + finalResult + "\n";
//                                Log.e("tag", "天津---查询车辆报告----finalResult====" + finalResult);
//                                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
//                                Toast.makeText(instances, "查询成功", Toast.LENGTH_LONG)
//                                        .show();
//                                Intent intent = new Intent(instances, TianjinReportActivity.class);
//                                intent.putExtra("tianjinReport", finalResult);
//                                intent.putExtra("plateNo", carsInforModel.getPlateRegion() + carsInforModel.getPlateNO());
//                                startActivity(intent);
//                            } catch (JSONException e) {
//                                e.printStackTrace();
//                            }
//                        }
////                        CommonUtils.hideLoadingDialog(instances);
////                        String str = result.substring(1, result.length() - 1);
//////                        if ("ok".equalsIgnoreCase(str)) {
//
////                        } else {
////                            Toast.makeText(instances, "开始失败，请重试", Toast.LENGTH_LONG)
////                                    .show();
////                        }
//                    }
//
//                    @Override
//                    public void onError(Response<String> response) {
//                        super.onError(response);
//                        String logStr2 = "\n" + "天津---查询车辆报告--onError" + "\n" +
//                                "result::" + response.body();
//                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
//                        UtilsLog.e("天津---查询车辆报告-onError==" + response.body());
//                        CommonUtils.hideLoadingDialog(instances);
//                    }
//                });
//    }
//
//    class TianJinCarReport {
//        String Brand, CarModel, BH, PDAType, IsNew, CarNO;
//
//        public String getBH() {
//            return BH;
//        }
//
//        public void setBH(String BH) {
//            this.BH = BH;
//        }
//
//        public String getPDAType() {
//            return PDAType;
//        }
//
//        public void setPDAType(String PDAType) {
//            this.PDAType = PDAType;
//        }
//
//        public String getBrand() {
//            return Brand;
//        }
//
//        public void setBrand(String brand) {
//            Brand = brand;
//        }
//
//        public String getCarModel() {
//            return CarModel;
//        }
//
//        public void setCarModel(String carModel) {
//            CarModel = carModel;
//        }
//
//        public String getIsNew() {
//            return IsNew;
//        }
//
//        public void setIsNew(String isNew) {
//            IsNew = isNew;
//        }
//
//        public String getCarNO() {
//            return CarNO;
//        }
//
//        public void setCarNO(String carNO) {
//            CarNO = carNO;
//        }
//
//        @Override
//        public String toString() {
//            return "TianJinCarReport{" +
//                    "Brand='" + Brand + '\'' +
//                    ", CarModel='" + CarModel + '\'' +
//                    ", BH='" + BH + '\'' +
//                    ", PDAType='" + PDAType + '\'' +
//                    ", IsNew='" + IsNew + '\'' +
//                    ", CarNO='" + CarNO + '\'' +
//                    '}';
//        }
//    }
    private void searchCar(String carPlate) {
        carsInforModels = new ArrayList<>();
        DownLineModel model = new DownLineModel();
        model.setPlateNO(carPlate);
        model.setType("0");
        model.setStatus("0,1,2,3,4");
        Gson gson = new Gson();
        String json_str = gson.toJson(model);
        UtilsLog.e("getDataSearchCarsByNOTianjin---json_str==" + json_str);
        UtilsLog.e("getDataSearchCarsByNOTianjin---url==" + SharedPreferencesUtils.getIP(this) + SEARCH_CARS);
        String logStr = "\n" + "天津车辆列表--查询----请求" + "\n" +
                "URL::" + SharedPreferencesUtils.getIP(instances) + SEARCH_CARS
                + "\n" + "json" + json_str;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

        OkGo.<String>post(SharedPreferencesUtils.getIP(this) + SEARCH_CARS).tag(this)
                .upJson(json_str)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        WaitDialog.show(instances, "查询中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        WaitDialog.dismiss();
                        String result = response.body();
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        UtilsLog.e("Tianjin-getDataSearchCarsByNO-newResult==" + newResult);

                        String logStr = "\n" + "天津车辆列表--查询----请求成功" + "\n" +
                                "result::" + response.body() + "\n" +
                                "URL::" + SharedPreferencesUtils.getIP(instances) + SEARCH_CARS;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

                        if (!TextUtils.isEmpty(newResult) && !"[[]]".equals(newResult) && !"[{}]".equals
                                (newResult) && !"[]".equals(newResult)) {
                            carsInforModels = JsonUtil.stringToArray(newResult, CarsInforModel[].class);
                            String logStr2 = "天津查询车辆列表---不为空--carsInforModels==" + carsInforModels;
                            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
                            if (carsInforModels.size() > 0) {
                                //弹窗
                                Popup(carsInforModels);
                            }
                        } else {
//                            Popup(carsInforModels);
                            Toast.makeText(instances, "此查询条件下无数据", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        WaitDialog.dismiss();
                        String errLog = "天津车辆列表--查询----请求失败---result==" + response.message() + "\n";
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, errLog.getBytes());
                        Toast.makeText(instances, "请求失败" + "\n" + "err:" + response.message(), Toast.LENGTH_SHORT).show();
                    }
                });
    }

    public void Popup(List<CarsInforModel> carsInforModels) {
        View popup_view = getLayoutInflater().inflate(R.layout.pop_window_layout, popPosition, false);
        Button btnPopCancel = (Button) popup_view.findViewById(R.id.btn_pop_cancel);
        Button btnPopDefine = (Button) popup_view.findViewById(R.id.btn_pop_define);
//        PopupWindow window = new PopupWindow(popup_view, ViewGroup.LayoutParams.WRAP_CONTENT
//                , ViewGroup.LayoutParams.WRAP_CONTENT);
        PopupWindow window = new PopupWindow(popup_view, ViewGroup.LayoutParams.WRAP_CONTENT
                , 480);
        window.setFocusable(true);//设置点击弹窗以外的地方关闭弹窗
//        window.showAsDropDown(view);
        window.setHeight(600);
        window.showAtLocation(popPosition, Gravity.BOTTOM, 0, 0);
        MyListView2 tianjinListView = (MyListView2) popup_view.findViewById(R.id.ac_tianjin_listView);
        tianjinAdapter = new TianjinAdapter(instances, carsInforModels);
        tianjinListView.setAdapter(tianjinAdapter);
        tianjinAdapter.notifyDataSetChanged();
        btnPopCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                window.dismiss();
            }
        });
        btnPopDefine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                String dateStr = popStartTime.getText().toString() + "\n" + popEndTime.getText().toString();
//                popStartTimeStr = popStartTime.getText().toString().trim();
//                popEndTimeStr = popEndTime.getText().toString().trim();
//                etRtmCarPlate.setText(dateStr);

                window.dismiss();
            }
        });
        tianjinListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                acTianjinVin.setText(carsInforModels.get(position).getVIN());
//                String jysj = carsInforModels.get(position).getDetectDate().substring(0,10);
                acTianjinPlatformSN.setText(carsInforModels.get(position).getPlatformSN());
                acTianjinJysj.setText(carsInforModels.get(position).getDetectDate());
                String logStr = "天津车辆列表---弹窗---onItemClick---clickPosition=" + position + "\n" + "选择的车牌号：" + carsInforModels.get(position).getPlateNO();
                Log.e("tag", logStr);
                PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                window.dismiss();
            }
        });
    }

    private void getPhoto(String vin, String detectDate, String platformSN, String carNo, String photoType, int index) {
        TianjinPhotoModel model = new TianjinPhotoModel();
        model.setDetectDate(detectDate);
        model.setVIN(vin);
        model.setCarNO(carNo);
        model.setPlatformSN(platformSN);
        model.setPhotoType(photoType);
        model.setPlateType("77");
        model.setIsNew("1");
        model.setStatus("77");
        Gson gson = new Gson();
        String jsonStr = gson.toJson(model);
        String logStr = "获取照片---url:;" + SharedPreferencesUtils.getIP(instances) + COM_SEARCH_CONFIRM + "\n" + "jsonStr===" + jsonStr;
        Log.e("tag", logStr);
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getIP(instances) + COM_SEARCH_CONFIRM)
                .tag(instances)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        WaitDialog.show(instances, "获取中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        WaitDialog.dismiss();
                        String result = response.body();
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        String logStr = "获取照片测试---请求成功---result===" + result + "\n" + "newResult" + newResult + "\n" + " URL::" + SharedPreferencesUtils.getIP(instances) + COM_SEARCH_CONFIRM;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        Log.e("tag", logStr);
                        try {
                            JSONArray jsonArray = new JSONArray(newResult);
//                            String url1 = jsonObject.getString("url1");
//                            String url2 = jsonObject.getString("url2");
//                            String url3 = jsonObject.getString("url3");
//                            String url4 = jsonObject.getString("url4");
//                            String logStr2 = "获取成功url1===" + url1 + "\n" + "url2===" + url2 + "\n" + "url3===" + url3 + "\n" + "url4===" + url4;
//                            Log.e("tag", "logStr2==" + logStr2);
//                            String photo1 = doGetImagefileByByte(url1);
//                            String photo2 = doGetImagefileByByte(url2);
//                            String photo3 = doGetImagefileByByte(url3);
//                            String photo4 = doGetImagefileByByte(url4);
//
//                            String logStr3 = "流转图片存到本地成功------" + "\n"
//                                    + "photo1==" + photo1 + "\n"
//                                    + "photo2==" + photo2 + "\n"
//                                    + "photo3==" + photo3 + "\n"
//                                    + "photo4==" + photo4;
//                            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr3.getBytes());
//                            Glide.with(instances).load(photo1).into(acIbTianjinPhoto1);
//                            Glide.with(instances).load(photo2).into(acIbTianjinPhoto2);
//                            Glide.with(instances).load(photo3).into(acIbTianjinPhoto3);
//                            Glide.with(instances).load(photo4).into(acIbTianjinPhoto4);
                            String base64Img = "";
                            base64Img = jsonArray.getJSONObject(0).getJSONObject("result").getString("base64Img").replace("data:image/jpeg;base64,", "");
                            byte[] decodedString = Base64.decode(base64Img, Base64.DEFAULT);
                            if (index == 0) {
                                Glide.with(instances).load(decodedString).into(acIbTianjinPhoto1);
                            } else if (index == 1) {
                                Glide.with(instances).load(decodedString).into(acIbTianjinPhoto2);
                            } else if (index == 2) {
                                Glide.with(instances).load(decodedString).into(acIbTianjinPhoto3);
                            } else if (index == 3) {
                                Glide.with(instances).load(decodedString).into(acIbTianjinPhoto4);
                            }

//                            new Thread(new Runnable() {
//                                @Override
//                                public void run() {
//                                    //请求详情
//                                    Bitmap photo4 = ImageUtils.getGossipImage(url1, instances);
//                                    PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, ("photo4==" + photo4).getBytes());
//                                }
//                            }).start();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        WaitDialog.dismiss();
                        Toast.makeText(instances, "获取失败" + "\n" + "err:" + response.message(), Toast.LENGTH_SHORT).show();
                        String logStr = "获取照片测试---onError----result==" + response.message();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                    }
                });
    }

    private void getPhoto0111(String vin, String detectDate, String platformSN, String carNo) {
        TianjinPhotoModel model = new TianjinPhotoModel();
        model.setDetectDate(detectDate);
        model.setVIN(vin);
        model.setCarNO(carNo);
        model.setPlatformSN(platformSN);
        model.setPhotoType("0111");
        model.setPlateType("77");
        model.setIsNew("1");
        model.setStatus("77");
        Gson gson = new Gson();
        String jsonStr = gson.toJson(model);
        String logStr = "获取照片---url:;" + SharedPreferencesUtils.getIP(instances) + COM_SEARCH_CONFIRM + "\n" + "jsonStr===" + jsonStr;
        Log.e("tag", logStr);
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getIP(instances) + COM_SEARCH_CONFIRM)
                .tag(instances)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        WaitDialog.show(instances, "获取中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        WaitDialog.dismiss();
                        acIbTianjinPhoto1 = null;
                        acIbTianjinPhoto1 = (ImageView) findViewById(R.id.ac_ib_tianjin_photo1);
//                            Glide.with(instances).load(null).into(acIbTianjinPhoto1);
                        String result = response.body();
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        String logStr = "获取照片0111---请求成功---result===" + result + "\n" + "newResult" + newResult + "\n" + " URL::" + SharedPreferencesUtils.getIP(instances) + COM_SEARCH_CONFIRM;
//                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        Log.e("tag", logStr);
                        try {
                            JSONArray jsonArray = new JSONArray(newResult);
                            String base64Img0111 = "";
                            base64Img0111 = jsonArray.getJSONObject(0).getJSONObject("result").getString("base64Img").replace("data:image/jpeg;base64,", "");
                            byte[] decodedString = Base64.decode(base64Img0111, Base64.DEFAULT);
                            Glide.with(instances).load(decodedString)
                                    .diskCacheStrategy(DiskCacheStrategy.NONE) //跳过磁盘缓存
                                    .skipMemoryCache(true)//跳过内存缓存
                                    .into(acIbTianjinPhoto1);
//                            String result_1 = Base64Util.base64Decode(base64Img0111, "UTF-8");
//                            String logStr2 = logStr + "\n" + "result_1===" + result_1 + "\n";
//                            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
//                            Glide.with(instances).load(result_1).into(acIbTianjinPhoto1);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        WaitDialog.dismiss();
                        Toast.makeText(instances, "获取失败" + "\n" + "err:" + response.message(), Toast.LENGTH_SHORT).show();
                        String logStr = "获取照片0111---onError----result==" + response.message();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                    }
                });
    }

    private void getPhoto0112(String vin, String detectDate, String platformSN, String carNo) {
        TianjinPhotoModel model = new TianjinPhotoModel();
        model.setDetectDate(detectDate);
        model.setVIN(vin);
        model.setCarNO(carNo);
        model.setPlatformSN(platformSN);
        model.setPhotoType("0112");
        model.setPlateType("77");
        model.setIsNew("1");
        model.setStatus("77");
        Gson gson = new Gson();
        String jsonStr = gson.toJson(model);
        String logStr = "获取照片---url:;" + SharedPreferencesUtils.getIP(instances) + COM_SEARCH_CONFIRM + "\n" + "jsonStr===" + jsonStr;
        Log.e("tag", logStr);
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getIP(instances) + COM_SEARCH_CONFIRM)
                .tag(instances)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        WaitDialog.show(instances, "获取中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        WaitDialog.dismiss();
                        acIbTianjinPhoto2 = null;
                        acIbTianjinPhoto2 = (ImageView) findViewById(R.id.ac_ib_tianjin_photo2);
                        String result = response.body();
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        String logStr = "获取照片0112---请求成功---result===" + result + "\n" + "newResult" + newResult + "\n" + " URL::" + SharedPreferencesUtils.getIP(instances) + COM_SEARCH_CONFIRM;
//                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        Log.e("tag", logStr);
                        try {
                            JSONArray jsonArray = new JSONArray(newResult);
                            String base64Img0112 = "";
                            base64Img0112 = jsonArray.getJSONObject(0).getJSONObject("result").getString("base64Img").replace("data:image/jpeg;base64,", "");
                            byte[] decodedString = Base64.decode(base64Img0112, Base64.DEFAULT);
                            Glide.with(instances).load(decodedString)
                                    .diskCacheStrategy(DiskCacheStrategy.NONE) //跳过磁盘缓存
                                    .skipMemoryCache(true)//跳过内存缓存
                                    .into(acIbTianjinPhoto2);
//                            String result_1 = Base64Util.base64Decode(base64Img0112, "UTF-8");
////                            String logStr2 = logStr + "\n" + "result_1===" + result_1 + "\n";
////                            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
//                            Glide.with(instances).load(result_1).into(acIbTianjinPhoto1);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        WaitDialog.dismiss();
                        Toast.makeText(instances, "获取失败" + "\n" + "err:" + response.message(), Toast.LENGTH_SHORT).show();
                        String logStr = "获取照片0112---onError----result==" + response.message();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                    }
                });
    }

    private void getPhoto0113(String vin, String detectDate, String platformSN, String carNo) {
        TianjinPhotoModel model = new TianjinPhotoModel();
        model.setDetectDate(detectDate);
        model.setVIN(vin);
        model.setCarNO(carNo);
        model.setPlatformSN(platformSN);
        model.setPhotoType("0113");
        model.setPlateType("77");
        model.setIsNew("1");
        model.setStatus("77");
        Gson gson = new Gson();
        String jsonStr = gson.toJson(model);
        String logStr = "获取照片---url:;" + SharedPreferencesUtils.getIP(instances) + COM_SEARCH_CONFIRM + "\n" + "jsonStr===" + jsonStr;
        Log.e("tag", logStr);
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getIP(instances) + COM_SEARCH_CONFIRM)
                .tag(instances)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        WaitDialog.show(instances, "获取中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        WaitDialog.dismiss();
                        acIbTianjinPhoto3 = null;
                        acIbTianjinPhoto3 = (ImageView) findViewById(R.id.ac_ib_tianjin_photo3);
                        String result = response.body();
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        String logStr = "获取照片0113---请求成功---result===" + result + "\n" + "newResult" + newResult + "\n" + " URL::" + SharedPreferencesUtils.getIP(instances) + COM_SEARCH_CONFIRM;

                        Log.e("tag", logStr);
                        try {
                            JSONArray jsonArray = new JSONArray(newResult);
                            String base64Img0113 = "";
                            base64Img0113 = jsonArray.getJSONObject(0).getJSONObject("result").getString("base64Img").replace("data:image/jpeg;base64,", "");
                            byte[] decodedString = Base64.decode(base64Img0113, Base64.DEFAULT);
                            Glide.with(instances).load(decodedString)
                                    .diskCacheStrategy(DiskCacheStrategy.NONE) //跳过磁盘缓存
                                    .skipMemoryCache(true)//跳过内存缓存
                                    .into(acIbTianjinPhoto3);

//                            String result_1 = Base64Util.base64Decode(base64Img0113, "UTF-8");
////                            String logStr2 = logStr + "\n" + "result_1===" + result_1 + "\n";
////                            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
//                            Glide.with(instances).load(result_1).into(acIbTianjinPhoto1);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        WaitDialog.dismiss();
                        Toast.makeText(instances, "获取失败" + "\n" + "err:" + response.message(), Toast.LENGTH_SHORT).show();
                        String logStr = "获取照片0113---onError----result==" + response.message();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                    }
                });
    }

    private void getPhoto0209(String vin, String detectDate, String platformSN, String carNo) {
        TianjinPhotoModel model = new TianjinPhotoModel();
        model.setDetectDate(detectDate);
        model.setVIN(vin);
        model.setCarNO(carNo);
        model.setPlatformSN(platformSN);
        model.setPhotoType("0209");
        model.setPlateType("77");
        model.setIsNew("1");
        model.setStatus("77");
        Gson gson = new Gson();
        String jsonStr = gson.toJson(model);
        String logStr = "获取照片---url:;" + SharedPreferencesUtils.getIP(instances) + COM_SEARCH_CONFIRM + "\n" + "jsonStr===" + jsonStr;
        Log.e("tag", logStr);
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getIP(instances) + COM_SEARCH_CONFIRM)
                .tag(instances)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        WaitDialog.show(instances, "获取中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        WaitDialog.dismiss();
                        acIbTianjinPhoto4 = null;
                        acIbTianjinPhoto4 = (ImageView) findViewById(R.id.ac_ib_tianjin_photo4);
                        String result = response.body();
                        String newResult = result.substring(1, result.length() - 1).replaceAll("\\\\", "");
                        String logStr = "获取照片0209---请求成功---result===" + result + "\n" + "newResult" + newResult + "\n" + " URL::" + SharedPreferencesUtils.getIP(instances) + COM_SEARCH_CONFIRM;
//                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        Log.e("tag", logStr);
                        try {
                            JSONArray jsonArray = new JSONArray(newResult);
                            String base64Img0209 = "";
                            base64Img0209 = jsonArray.getJSONObject(0).getJSONObject("result").getString("base64Img").replace("data:image/jpeg;base64,", "");
                            byte[] decodedString = Base64.decode(base64Img0209, Base64.DEFAULT);
                            Glide.with(instances).load(decodedString)
                                    .diskCacheStrategy(DiskCacheStrategy.NONE) //跳过磁盘缓存
                                    .skipMemoryCache(true)//跳过内存缓存
                                    .into(acIbTianjinPhoto4);
//                            String result_1 = Base64Util.base64Decode(base64Img0209, "UTF-8");
//                            String logStr2 = logStr + "\n" + "result_1===" + result_1 + "\n";
//                            PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr2.getBytes());
//                            Glide.with(instances).load(result_1).into(acIbTianjinPhoto4);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        WaitDialog.dismiss();
                        Toast.makeText(instances, "获取失败" + "\n" + "err:" + response.message(), Toast.LENGTH_SHORT).show();
                        String logStr = "获取照片0209---onError----result==" + response.message();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                    }
                });
    }

    private void getQuery(String clsbdh, String jysj) {
        TianjinModel model = new TianjinModel();
        model.setClsbdh(clsbdh);
        model.setJysj(jysj);
        Gson gson = new Gson();
        String jsonStr = gson.toJson(model);
        String logStr = "天津-----获取流水记录---照片流---jsonStr====" + jsonStr + "\n" + "URL::" + SharedPreferencesUtils.getIP(instances) + GET_TJ_PHOTO_URL;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
        OkGo.<String>post(SharedPreferencesUtils.getIP(instances) + GET_TJ_PHOTO_URL).tag(instances)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        String logStr = "天津---请求成功---result==" + result;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        try {
                            JSONObject jsonObject = new JSONObject(result);
                            String code = jsonObject.getString("code");
                            if (code.equals("200")) {
                                Toast.makeText(instances, "查询成功", Toast.LENGTH_SHORT).show();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                    }
                });
    }

    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
            case DATE_DIALOG:
                return new DatePickerDialog(this, mdateListener, mYear, mMonth, mDay);
        }
        return null;
    }

    private DatePickerDialog.OnDateSetListener mdateListener = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            mYear = year;
            mMonth = monthOfYear;
            mDay = dayOfMonth;
            display(acTianjinJysj);
        }
    };

    /**
     * 设置日期 利用StringBuffer追加
     */
    public void display(TextView tv) {
        tv.setText(new StringBuffer().append(mYear).append("-").append(mMonth + 1).append("-").append(mDay));
        String time = tv.getText().toString().trim();
        UtilsLog.e("===22=" + DateUtil.getDateForSurplus(time));
        tv.setText(DateUtil.getDateForSurplus(time));
    }
}
